<div class="modal fade " id="addReportTemplateInfoModal"  role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">模板上传</h3>
            </div>

            <!-- form start -->
            <form class="form-horizontal" role="form" id="addReportTemplateInfoForm"  method="post" action="/reporttemplate/addreporttemplate" enctype="multipart/form-data">
                <div id="toolbar">
                    <div class="form-group">
                        <input id="paramValue" name="paramValue" type="text" style="display:none;">
                        <label class="col-sm-2 control-label" for="remarkLabel">备注</label>
                        <div class="col-sm-5">
                            <input id="remark" name="remark" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <input id="opType" name="opType" type="text" style="display:none;">
                        <label class="col-sm-2 control-label" for="opTypeLabel">预览模式</label>
                        <div class="col-sm-5">
                            <select id="opTypeList" name="opTypeList" class="form-control">
                                <option value="2">数据分析预览</option>
                    	        <option value="0">分页预览</option>
                    		    <option value="1">填报预览</option>
                    	        <option value="3">新填报预览</option>
                    	        <option value="4">决策报表预览</option>
                    	    </select>
                    	</div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="inputFileLabel">模板文件</label>
                        <div class="col-sm-5">
                            <input type="file" id="file" name="file">
                        </div>
                    </div>
                </div>
                <div class="box-body">
                        <table id="reportDictTable" data-toggle="table" data-url="/reporttemplate/queryTemplateDictList"
                               data-click-to-select="true" data-single-select="false" width="20" data-checkbox-header="false"
                               data-toolbar="toolbar" data-query-params="queryParams1"
                               data-pagination="true" data-page-size="4" data-sort-name="labelName" >
                            <thead>
                                <tr>
                                    <th data-field="state" data-checkbox="true">选择</th>
                                    <th data-field="labelName" data-sortable="true">参数名</th>
                                    <th data-field="paramName"  data-sortable="true">参数字段名</th>
                                </tr>
                            </thead>
                        </table>
                </div>
                <div class="box-footer">
                    <button type="button" class="btn btn-danger pull-left" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary pull-right" onclick="addreporttemplate()">上传</button>
                </div>
            </form>
        </div>
    </div>
</div>
<#include "../public/js.ftl" >
<#include "../public/css.ftl">
<script>
    function addReportParamInit() {
        $("#remark").val("");
        $("#file").val("");
        $("#paramValue").val("");
        $("#opType").val("0");
    }

    function addreporttemplate() {
        //根据参数表所选行，组装param参数
        var paramValue = "";

        var rows = $("#reportDictTable").bootstrapTable('getSelections', function (row) {
                  return row;
        });

        if(rows.length > 0) {
            var data = $('#reportDictTable').bootstrapTable('getData');

            for(var i=0; i<rows.length; i++){
                if(paramValue.length == 0) {
                    paramValue = rows[i].paramName;
                } else {
                    paramValue = paramValue + "|" + rows[i].paramName;
                }
            }
        }

        $("#paramValue").val(paramValue);

        var filename = $("#file").val();

        if (filename == null || filename == undefined || filename == "" || filename.trim() == "") {
            toastr['error']("未选择上传文件", '异常');
            return;
        }

        var pointIndex = filename.lastIndexOf(".");
        var fileLength = filename.length;
        var suffix = filename.substring(pointIndex + 1,fileLength);

        if (suffix != "cpt" && suffix != "frm") {
            toastr['error']("上传文件后缀名必须是cpt或frm", '异常');
            return;
        }

        var  opList = document.getElementById("opTypeList");
        var index = opList.selectedIndex;

        $("#opType").val(opList.options[index].value);
        var opType = $("#opType").val();

        var remark = $("#remark").val();

        //上传文件
		var data = {
		    remark : remark,
            paramValue : paramValue,
            opType : opType
		};

		fileReq("/reporttemplate/addreporttemplate","file",data,function(result){
			if(result.success) {
				toastr['success']('文件上传成功', '提示');
				addReportParamInit();
				$("#addReportTemplateInfoModal").modal("hide");
				$("#templateTable").bootstrapTable("refresh");
			} else {
				toastr['error'](result.msg, '提示');
			}
		});
    }
</script>
